﻿using System.Web.Mvc;
using Dexter.Logger.Contracts;
using Dexter.Services;
using Dexter.Web.Mvc.Filters;
using Dexter.Web.Mvc.ViewModel.Backoffice.ViewsData.StatisticsController;
using Dexter.Web.Utils;

namespace Dexter.Web.Mvc.Controllers.Backoffice {
	[Authorize]
	[DexterCallFilter ( true )]
	public class StatisticsController : BackOfficeControllerBase {
		readonly IReferrerService referrerService;

		/// <summary>
		/// Initializes a new instance of the <see cref="StatisticsController"/> class.
		/// </summary>
		/// <param name="configurationService">The configuration service.</param>
		/// <param name="webUtils">The web utils.</param>
		/// <param name="logger">The logger.</param>
		/// <param name="urlBuilder">The URL builder.</param>
		/// <param name="contactService">The contact service.</param>
		public StatisticsController ( IConfigurationService configurationService , IWebUtils webUtils , ILogger logger , IUrlBuilder urlBuilder , IContactService contactService , IReferrerService referrerService ) : base ( configurationService , webUtils , logger , urlBuilder , contactService ) {
			this.referrerService = referrerService;
		}

		[AcceptVerbs ( HttpVerbs.Get )]
		public ActionResult Referrers( int? page) {
			int pageIndex = page ?? 1;

			pageIndex--;

			var data = base.GetViewData ( new ReferrertsViewData ( base.WebUtils , base.Configuration , base.UrlBuilder ) );
			data.Referrers = referrerService.GetCompleteList ( pageIndex , 20 , false );

			return View ( data );
		}
	}
}
